import { CustomTableInterface } from '@/components/ProTable/interface';
import { PublicInterface } from '@/interface/public';
import { useEducationExperienceForm } from '../form/use-educationExperienceForm';

/**
 * 教育经历
 */

export function useEducationExperienceData(proTableBox: PublicInterface.ProTableValue, drawerObj: any) {
  const { educationExperienceForm, saveAddEducationExperienceForm } = useEducationExperienceForm(proTableBox);

  let educationExperienceData = reactive<CustomTableInterface>({
    initParam: {
      rosterId: ''
    },
    // 表格配置项
    columns: [
      { prop: 'operation', label: 'operation', fixed: 'left', width: 180 },
      {
        label: '开始日期',
        prop: 'start'
      },
      {
        label: '结束日期',
        prop: 'end'
      },
      {
        label: '学校名称',
        prop: 'schoolName'
      },
      {
        label: '主修专业',
        prop: 'major'
      },
      {
        label: '是否毕业',
        prop: 'flagGraduate',
        enum: statusYesOrNo
      },
      {
        label: '取得学历',
        prop: 'educationName'
      },
      {
        prop: 'remark',
        label: 'remark'
      }
    ],

    headButtonList: [
      {
        label: 'add',
        type: 'primary',
        icon: 'el-Plus',
        // permissionCode: 'roster:saveStudy',
        methods: () => {
          const params = {
            rosterId: drawerObj.value.id
          };
          formOpen(educationExperienceForm, '新增教育经历', params);
        }
      }
    ],
    rowButtonList: [
      {
        label: 'edit',
        type: 'primary',
        // permissionCode: 'roster:saveStudy',
        methods: row => {
          const params = {
            rosterId: drawerObj.value.id,
            ...row
          };
          formOpen(educationExperienceForm, '编辑教育经历', params);
        },
        attrs: {
          link: true
        }
      },
      {
        label: 'delete',
        type: 'danger',
        // permissionCode: 'roster:removeStudy',
        methods: row => {
          const name = `${transitionLanguages('button', 'delete')}【${row.schoolName}】教育经历`;
          const params = {
            id: row.id
          };
          useHandleData(educationInfoDelete, params, name, proTableBox.value?.getTableList);
        },
        attrs: {
          link: true
        }
      }
    ]
  });

  return { educationExperienceData, educationExperienceForm, saveAddEducationExperienceForm };
}
